package com.bentley.kotlindemo.db.dao

import androidx.paging.DataSource
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Delete
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.bentley.kotlindemo.db.entity.Author
import kotlinx.coroutines.flow.Flow

/**
 * <pre>
 *  ┌────────────────────────────────────────────
 *  │ @author  Lee  @date 2021/3/23 17:57
 *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
 *  │ @desc
 *  └────────────────────────────────────────────
 * </pre>
 */

@Dao
interface AuthorDao {
    @Query("SELECT * FROM author ORDER BY name")
    fun getPlants(): Flow<List<Author>>

//    @Query("SELECT * FROM author WHERE growZoneNumber = :growZoneNumber ORDER BY name")
//    fun getPlantsWithGrowZoneNumber(growZoneNumber: Int): Flow<List<Author>>

    @Query("SELECT * FROM author WHERE id = :plantId")
    fun getPlant(plantId: String): Flow<Author>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAll(plants: List<Author>)

    @Delete
    suspend fun deleteAuthor(author: Author)

    @Query("Delete  FROM author WHERE 1=1")
    suspend fun deleteAllAuthor()

    //分页用
    @Query("SELECT * FROM author ORDER BY name COLLATE NOCASE ASC")
    fun getAllStudent(): DataSource.Factory<Int, Author>
}